import {app, BrowserWindow, ipcRenderer,Notification} from "electron"
let sysStorage:any = {}

export class Channel {
  private windowAll: any;

  constructor(windowAll?: any) {
    this.windowAll = windowAll;
  }

  //最大化窗口
  maxWin(...args:any)  {
    console.log('maxWin', args);
    const windowName = args[0] || 'mainWindow'; // 默认为主窗口
    const win = this.windowAll?.[windowName];

    if (win && !win.isDestroyed()) {
      win.isMaximized() ? win.unmaximize() : win.maximize();
    } else {
      console.error(`Window ${windowName} not found or destroyed`);
    }
  }
  //最小化窗口
  minWin(...args:any)  {
    console.log('minWin', args);
    const windowName = args[0] || 'mainWindow';
    const win = this.windowAll?.[windowName];

    if (win && !win.isDestroyed()) {
      win.minimize();
    } else {
      console.error(`Window ${windowName} not found or destroyed`);
    }
  }
  //关闭窗口
  closeWin(...args:any) {
    console.log('closeWin', args);
    const windowName = args[0] || 'mainWindow';
    const win = this.windowAll?.[windowName];

    if (win && !win.isDestroyed()) {
      win.close();
    } else {
      console.error(`Window ${windowName} not found or destroyed`);
    }
  }

  //系统通知
  notify(...args:any) {
    console.log('closeWin', args);
    const windowName = args[0] || 'mainWindow';
    const win = this.windowAll?.[windowName];

    const notification = new Notification({
      title: '您有一个新呼叫',
      body: '来自群众的呼叫'
    });

    notification.on('click', () => {
      if (win && !win.isDestroyed()) {
        if (win.isMinimized()) {
          win.restore();
        }
        win.show();
        win.focus();
      }
    });

    notification.show();
  }
  changeWin(...args:any) {
    // const windowName = args[0] || 'mainWindow';
    // const win = this.windowAll?.[windowName];
    //
    // if (win && !win.isDestroyed()) {
    //   win.isMaximized() ? win.unmaximize() : win.maximize();
    // } else {
    //   console.error(`Window ${windowName} not found or destroyed`);
    // }
  }

  //设置或获取Storage
  getStorage(...args:any) {
    return sysStorage
  }

  dragWin(app:any,BrowserWindow:any) {
    //if (BrowserWindow) BrowserWindow.startDragging(); // 开始拖动窗口
  }
}
